package com.dream.model.app;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;

import com.dream.model.base.AppUserModelBase;
import com.google.common.collect.Lists;

@MappedSuperclass
public class AppAbstractUser extends AppUserModelBase implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(generator = "mycode")
	@GenericGenerator(name = "mycode", strategy = "assigned")
	@Column(name = "id")
	private String id;

	@Column(name="password")
	private String password;

	@Column(name="status")
	@Enumerated(EnumType.STRING)
	private UserStatus status;
	
	@Column(name="name")
	private String name;
	
	@Column(name="mobile")
	private String mobile;
	
	@Column(name="position_id")
	private Long positionId;
	
	@Column(name="org_id")
	private Long orgId;
	
	@Column(name="image_id")
	private Long imageId;
	
	@Column(name="last_login_time")
	private Date lastLoginTime;
	
	@Column(name="wrong_pwd_count")
	private Integer wrongPwdCount;
	
	@Column(name="login_succ_count")
	private Long loginSuccCount;
	
	@Transient
	private List<AppGroup> groups = Lists.newArrayList();
	
	@Transient
	private AppOrg appOrg;
	
	@Transient
	private AppPosition position;
	
	@Transient
	private AppImage image;
	
	public Long getImageId() {
		return imageId;
	}

	public void setImageId(Long imageId) {
		this.imageId = imageId;
	}
	
	public Long getPositionId() {
		return positionId;
	}

	public void setPositionId(Long positionId) {
		this.positionId = positionId;
	}

	public Long getOrgId() {
		return orgId;
	}

	public void setOrgId(Long orgId) {
		this.orgId = orgId;
	}

	
	public AppImage getImage() {
		return image;
	}
	
	public void setImage(AppImage image) {
		this.image = image;
	}

	public List<AppGroup> getGroups() {
		return groups;
	}

	public void setGroups(List<AppGroup> groups) {
		this.groups = groups;
	}

	public AppPosition getPosition() {
		return position;
	}

	public void setPosition(AppPosition position) {
		this.position = position;
	}

	public UserStatus getStatus() {
		return status;
	}

	public void setStatus(UserStatus status) {
		this.status = status;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}


	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public Date getLastLoginTime() {
		return lastLoginTime;
	}

	public void setLastLoginTime(Date lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}

	public Integer getWrongPwdCount() {
		return wrongPwdCount;
	}

	public void setWrongPwdCount(Integer wrongPwdCount) {
		this.wrongPwdCount = wrongPwdCount;
	}

	public Long getLoginSuccCount() {
		return loginSuccCount;
	}

	public void setLoginSuccCount(Long loginSuccCount) {
		this.loginSuccCount = loginSuccCount;
	}

	public AppOrg getAppOrg() {
		return appOrg;
	}

	public void setAppOrg(AppOrg appOrg) {
		this.appOrg = appOrg;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AppAbstractUser other = (AppAbstractUser) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	public static  enum UserStatus {
		verify,active,block,delete,exception,expire;
		
		public static Collection<UserStatus> activeList = Lists.newArrayList();
		static {
			activeList.add(active);
			activeList.add(expire);
			activeList.add(block);
		}
	}
}
